/**
 * 
 */
package br.com.ufrn.aipetro.ga.model.persist.hibernate;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import br.com.ufrn.aipetro.ga.domain.entity.plant.Plant;
import br.com.ufrn.aipetro.ga.domain.entity.unit.Unit;
import br.com.ufrn.aipetro.ga.model.persist.hibernate.util.HibernateUtil;
import br.com.ufrn.aipetro.ga.persist.interfaces.PlantDao;

/**
 * 
 * @author Lucas
 *
 */
public class HibernatePlantDao extends PlantDao {
	
	Session session;
	Class entityClass;
	
	public HibernatePlantDao(Class entityClass) {
		this.session = HibernateUtil.getSessionFactory().getCurrentSession();
		this.entityClass = entityClass;
		basicDao = new HibernateBasicDao<Plant>(session, entityClass);
	}
	
	public List<Plant> searchByUnit(Unit unit) {
		return (List<Plant>)session.createCriteria(Plant.class)
				.createCriteria("unit")
				.add(Example.create(unit)
						.enableLike(MatchMode.START)
						.excludeZeroes())
				.list();
	}
}
